package com.sanploy.fed.push.dao;

import com.sanploy.fed.push.bean.ZkyUser;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2017/4/7.
 */
@Repository
@Transactional
public interface UserDao extends CrudRepository<ZkyUser,Long> {

    @Query(value = "SELECT * FROM zkyuser WHERE login_name = ? and login_pwd = ?",nativeQuery = true)
    public ZkyUser judgeLogin(String name, String pwd);

    @Query(value = "SELECT * FROM zkyuser WHERE token = ?",nativeQuery = true)
    public ZkyUser judgeToken(String token);

    @Modifying(clearAutomatically = true)
    @Query(value = "INSERT INTO zkyuser (login_name,login_pwd,nick_name) VALUES(?,?,?);",nativeQuery = true)
    public int insertUser(String loginName, String loginPwd, String nickName);

    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE zkyuser SET token = ? WHERE id = ?",nativeQuery = true)
    public int updateToken(String token, long id);

}
